package com.leo.springbootmultithreadbasic.java8;

import com.leo.springbootmultithreadbasic.buildthread.usethreadpool.ThreadPoolConfig;
import org.apache.commons.logging.LogFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author Leo
 * @version V1.0
 */
public class ThreadPoolUsage {

    private static final Logger logger = LoggerFactory.getLogger(ThreadPoolUsage.class);

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        test();
    }



    /**
     * 使用线程池
     */
    public static void test() throws ExecutionException, InterruptedException {

        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolConfig().threadPoolExecutor;

        CompletableFuture<String> future1 = CompletableFuture.supplyAsync(CompletableFutureDemo::callRpc1, threadPoolExecutor);

        future1.get();

    }

    public static String callRpc1() {
        // 模拟业务处理耗时
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        logger.debug("rpc call 1");
        return "rpc call 1";
    }



}
